use super::*;

mod class_definition;
mod coverage;
mod device;
mod feature;
mod lookup;
mod lookup_chained_context;
mod lookup_context;
mod range_record;
mod record_list;
mod script;
mod variations;

pub use class_definition::*;
pub use coverage::*;
pub use device::*;
pub use feature::*;
pub use lookup::*;
pub use lookup_chained_context::*;
pub use lookup_context::*;
pub use range_record::*;
pub use record_list::*;
pub use script::*;
pub use variations::*;

/// An index in [`ScriptList`].
pub type ScriptIndex = u16;
/// An index in [`LanguageSystemList`].
pub type LangIndex = u16;
/// An index in [`FeatureList`].
pub type FeatureIndex = u16;
/// An index in [`LookupList`].
pub type LookupIndex = u16;
/// An index in [`FeatureVariations`].
pub type VariationIndex = u32;

/// A list of [`Script`] records.
pub type ScriptList<'a> = RecordList<'a, Script<'a>>;
/// A list of [`LanguageSystem`] records.
pub type LangSysList<'a> = RecordList<'a, LangSys<'a>>;
/// A list of [`Feature`] records.
pub type FeatureList<'a> = RecordList<'a, Feature<'a>>;

pub fn parse_extension_lookup<'a, T: 'a>(data: &'a [u8], parse: impl FnOnce(&'a [u8], u16) -> Option<T>) -> Option<T> {
	let mut s = Stream::new(data);
	let format = s.read::<u16>()?;
	match format {
		1 => {
			let kind = s.read::<u16>()?;
			let offset = s.read::<Offset32>()?.to_usize();
			parse(data.get(offset..)?, kind)
		}
		_ => None,
	}
}
